package com.secneo.appshare;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

import com.secneo.appshare.api.LocalStore;

public class AppShareApplication extends Application 
{
	private List<Activity> activityList = new LinkedList<Activity>();
	private static AppShareApplication instance;
	
	@Override
	public void onCreate()
	{
		super.onCreate();
		instance = this;
		LocalStore.getLocaleStoreInstance(this);
	}

	public static AppShareApplication getInstance()
	{
		return instance;
	}

	public void addActivity(Activity activity)
	{
		activityList.add(activity);
	}
	
	public void finishActivity(String activityName)
	{
		for(int i=0; i<activityList.size(); i++)
		{
			try
			{
				Activity activity = activityList.get(i);
				if(activity.getClass().getName().equals(activityName))
				{
					activity.finish();
					activityList.remove(i);
					return;
				}
				
			} catch (Exception ex)
			{
				ex.printStackTrace();				
			}
		}
	}

	public void exit()
	{
		for (Activity activity : activityList)
		{
			try
			{
				activity.finish();
				
			} catch (Exception ex)
			{
				ex.printStackTrace();
			}
		}
		System.exit(0);
	}
}
